from abc import ABC, abstractmethod
from typing import Dict, List


class DocCombiner(ABC):
    @abstractmethod
    def combine(self, docs: List[Dict]) -> str:
        raise NotImplementedError
    
def doc_combiner_factory(splitter_id: str) -> DocCombiner:
    return {
        "TextParagraphSplitter": ParagraphDocCombiner(),
        "LlmTextSplitter": LlmSplitDocCombiner(),
    }[splitter_id]
    
class ParagraphDocCombiner(DocCombiner):
    def combine(self, docs: List[Dict]) -> str:
        context_content = "\n\n".join(f'paragraph_index:{doc["meta"]["paragraph_index"]} " + \
            "segment_index:{doc["meta"]["segment_index"]}:\n{doc["text"]}' for doc in docs) + \
            "\n注：paragraph_index代表在文章中的第几段落，segment_index代表在段落中的第几段分割文本"
        return context_content
    
class LlmSplitDocCombiner(DocCombiner):
    def combine(self, docs: List[Dict]) -> str:
        context_content = "\n\n".join(f'{doc["text"]}' for doc in docs) + \
            "\n注：“论文选段”为节选自原论文的内容；“小结”为AI关于选段内容的理解和总结"
        return context_content